#ifndef DATETIME_H_INCLUDED_
#define DATETIME_H_INCLUDED_
+#include <cstdint>
#include <ctime>
#include <QtGlobal>
// Temporary: Override the standard, also handle time_t 0 as invalid.
bool isValid() const {
- return date().isValid() && time().isValid() && toTime_t() > 0;
+ return QDateTime::isValid() && (toSecsSinceEpoch() != 0);
}
// Like toString, but with subsecond time that's included only when
return toUTC().toString(QStringLiteral("yyyy-MM-ddTHH:mm:ssZ"));
}
}
+
+ // QDateTime::toTime_t was deprecated in Qt5.8, and deleted in Qt6.
+ uint32_t toTime_t() const {
+ if (!QDateTime::isValid()) {
+ return -1;
+ }
+ long long secs_since_epoch = toSecsSinceEpoch();
+ if ((secs_since_epoch < 0) || (secs_since_epoch > 0xfffffffe)) {
+ return -1;
+ }
+ return secs_since_epoch;
+ }
};
} // namespace gpsbabel